﻿using BasicInformation.API.Application.Command.FuelCostsCommand;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.API.Application.CommandHandler.FuelCostsCommandHandler
{
    public class FuelCostsBatchDeleteCommandHandler : IRequestHandler<FuelCostsBatchDeleteCommand, int>
    {
        private readonly IFuelCostsRepository fuelCostsRepository;

        public FuelCostsBatchDeleteCommandHandler(IFuelCostsRepository fuelCostsRepository)
        {
            this.fuelCostsRepository = fuelCostsRepository;
        }

        public async Task<int> Handle(FuelCostsBatchDeleteCommand request, CancellationToken cancellationToken)
        {
            var Id = request.Ids.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
            var list = await fuelCostsRepository.GetListInfo(x => Id.Contains(x.Id));
            foreach (var item in list)
            {
                item.IsDel=true;
            }
            return await fuelCostsRepository.UpdateRange(list);
        }
    }
}
